<script>
	var url;
	$(document).ready(function(){
	//tambah data
	newData = function (){
		$('#dialog').dialog({
			title: 'Tambah Data Master',
			width: 475,
			height: 300,
			closed: true,
			cache: false,
			href: base_url+'master/add',
			modal: true
		});
		 
		$('#dialog').dialog('open');
		url = base_url+'master/save/add';
	}
	
	
	// save data
	saveData = function(){
		$('#form1').form('submit',{
			url: url,
			onSubmit: function(){
				return $(this).form('validate');
			},
			success: function(result){
				//alert(result);
				var result = eval('('+result+')');
				if (result.success){
					$('#dialog').dialog('close');		// close the dialog
					$('#dg').datagrid('reload');		// reload the user data
				} else {
					ShowMessageError(result.msg);
				}
			}
		});
	}
	//end saveData
	
	detail = function (id){
			//var row = $('#dg').datagrid('getSelected');
			//if (row){
				$('#dialogDetail').dialog({
					title: 'Detail Data Master',
					width: 450,
					height: 475,
					closed: true,
					cache: false,
					href: base_url+'master/detail/'+id,
					modal: true
				});
				
				$('#dialogDetail').dialog('open');  
				url = base_url+'master/save/edit';
			// }
		}
		//end detail
	$(function(){
			$('#dg').datagrid({url:"<?=base_url()?>master/grid"});	
			//$('#dg').datagrid('enableFilter'); 			
		});
	actionbutton = function(value, row, index){
			var col;
			col = '<a href="#" onclick="detail(\''+row.id+'\');" class="easyui-linkbutton" iconCls="icon-edit" plain="false">Detail</a>';
			return col;
		}
		
	//# Tombol Bawah
	//	$(function(){
	//		var pager = $('#dg').datagrid().datagrid('getPager');	// get the pager of datagrid
	//		pager.pagination({
	//			buttons:[
		//			{
		//				iconCls:'icon-add',
		//				text:'Tambah Data',
	//					handler:function(){
		//					newData();
		//				}
	//				}/* ,
	//				{
	//					iconCls:'icon-print',
	//					text:'Export PDF',
	//					handler:function(){
		//					window.open('<?=base_url().'nominasi/pdf'?>');
		//				}
	//				} */
	//			]
		//	});			
		//});
	});
</script>
<table id="dg" title="Kelola Data Master" data-options="
			rownumbers:true,
			singleSelect:true,
			autoRowHeight:false,
			pagination:true,
			pageSize:30,
			fit:true,
			toolbar:'#toolbar',
			">
	<thead>
		<tr>
			<!--<th field="nama_program" sortable="true" width="100">Program</th>-->
			<th field="CODE" sortable="true" width="100">Code</th>
			<th field="NAME" sortable="true" width="80">Nama</th>
			<th field="DESCRIPTION" sortable="true" width="200">Deskripsi</th>
			<th field="action" align="center" formatter="actionbutton" width="130">Aksi</th>
		</tr>
	</thead>
</table>
<div id="toolbar" style="padding:5px;height:auto">
	<div style="margin-bottom:5px">
		
	</div>
	<div>
		<table width="700" border="0">
		  <!--tr>
			<td>Fakultas</td>
			<td>: 
				<select id="s_kd_fakultas" name="s_kd_fakultas" style="width:290px;">
					
				</select>
			</td>
			<td>&nbsp;</td>
			<td>&nbsp;</td>
			<td>&nbsp;&nbsp;<a href="#" onclick="filter()" class="easyui-linkbutton" iconCls="icon-search">Filter</a></td>
		  </tr-->
		</table>
	</div>
</div>
